<?php
class Pageley_Commerce_Command_CancelOrder extends Pageley_Controller_Command_TransactionalReadWrite {

	private $orderId;

	public function setOrderId($orderId) {
		$this->orderId = $orderId;
	}

    protected function executeInternal() {
        $unitOfWork = $this->getUnitOfWork();
    	$order = $unitOfWork->find(Pageley_Commerce_Domain_Order::type(),
            $this->orderId);
        if($order === null) {
            throw new Pageley_Domain_Exception(
                new Pageley_I18n_Message("error.commerce.invalidOrderCancelled"));
        }
        $order->cancel();
    }
}